﻿using Microsoft.Practices.Unity;

namespace UnityDemo.DemoCode
{
    //http://msdn.microsoft.com/en-us/library/ff662050(v=pandp.20).aspx
    //This method is useful if you've registered multiple types with the same Type but different names.
    //Be aware that this method does NOT return an instance for the default (unnamed) registration.
    public class ResolveAllDemo :IDemo
    {
        public ResolveAllDemo()
        {
            var container = UnityProvider.UnityInstanceProvider.NewUnityInstance;

            container.RegisterInstance<IUnityContainer>(container);
            container.RegisterType<IParser, SuperParser>("super");
            container.RegisterType<IParser, DefaultParser>("def");
            container.RegisterType<IParser, BasicParser>();


            // Only two instances will be shown as the default registered type is not shown
            foreach (var registeredMember in container.ResolveAll<IParser>())
            {
                LoggingUtility.LogerInstance.Logger.Write(registeredMember);
            }
        }

        #region Resovle Demo

        public class DefaultParser : IParser
        {
            public override string ToString()
            {
                return "DefaultParser";
            }
        }

        public class BasicParser : IParser
        {
            public override string ToString()
            {
                return "BasicParser";
            }
        }

        public class SuperParser : IParser
        {
            public override string ToString()
            {
                return "SuperParser";
            }
        }

        public interface IParser
        {
        }

        #endregion Resovle Demo
    }
}